{include file="common/head"/}
<div class="admin-main layui-anim layui-anim-upbit" ng-app="hd" ng-controller="ctrl">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>{$title}</legend>
    </fieldset>
    <form class="layui-form layui-form-pane">
        <div class="layui-form-item">
            <label class="layui-form-label">标题</label>
            <div class="layui-input-4">
                <input type="text" name="title" ng-model="field.title" lay-verify="required" placeholder="请输入标题" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">是否置顶</label>
            <div class="layui-input-4">
                <input type="radio" name="top"  ng-model="field.top" ng-checked="field.top==0" ng-value="0" title="否">
                <input type="radio" name="top"  ng-model="field.top" ng-checked="field.top==1" ng-value="1"  title="是">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">是否重要</label>
            <div class="layui-input-4">
                <input type="radio" name="important"  ng-model="field.important" ng-checked="field.important==0" ng-value="0" title="否">
                <input type="radio" name="important"  ng-model="field.important" ng-checked="field.important==1" ng-value="1"  title="是">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">帖子正文</label>
            <div class="layui-input-4">
                <textarea id="noticeText" style="display: none;">{{field.text}}</textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" class="layui-btn" lay-submit="" lay-filter="submit">{:lang('submit')}</button>
                <a href="{:url('lists')}" class="layui-btn layui-btn-primary">{:lang('back')}</a>
            </div>
        </div>
    </form>
</div>
{include file="common/foot"/}
<script src="/static/common/js/angular.min.js"></script>
<script>
    var m = angular.module('hd',[]);
    m.controller('ctrl',['$scope',function($scope) {
        $scope.field = '{$info|raw}'!='null'?{$info|raw}:{id:'', title:'', top:'', important:'', text:''};
        layui.use(['form', 'layer','layedit'], function () {
            var form = layui.form, $ = layui.jquery,layedit = layui.layedit;
            layedit.set({
                uploadImage: {
                    url: "{:url('UpFiles/editUploadLayui')}",
                    type: 'post'
                }
            });
            layedit.sync(noticeText)
            var noticeText = layedit.build('noticeText');
            form.on('submit(submit)', function (data) {
                // 提交到方法 默认为本身
                data.field.id = $scope.field.id;
                data.field.text = layedit.getContent(noticeText);
                console.log(data)
                var loading = layer.load(1, {shade: [0.1, '#fff']});
                $.post("", data.field, function (res) {
                    layer.close(loading);
                    if (res.code > 0) {
                        layer.msg(res.msg, {time: 1800, icon: 1}, function () {
                            location.href = res.url;
                        });
                    } else {
                        layer.msg(res.msg, {time: 1800, icon: 2});
                    }
                });
            });

        });
    }]);
</script>